<?php

/**
 * This is the model class for table "client_contact_person".
 *
 * The followings are the available columns in table 'client_contact_person':
 * @property integer $id
 * @property string $cp_lastname
 * @property string $cp_firstname
 * @property string $cp_middlename
 * @property integer $cp_cellphone_no
 * @property integer $cp_telephone_no
 * @property string $cp_email
 * @property integer $establishment_id
 *
 * The followings are the available model relations:
 * @property ClientBackground[] $clientBackgrounds
 * @property Establishment $establishment
 */
class ClientContactPerson extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return ClientContactPerson the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'client_contact_person';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cp_lastname, cp_firstname, establishment_id', 'required'),
			array('cp_cellphone_no, cp_telephone_no, establishment_id', 'numerical', 'integerOnly'=>true),
			array('cp_lastname, cp_firstname, cp_middlename, cp_email', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, cp_lastname, cp_firstname, cp_middlename, cp_cellphone_no, cp_telephone_no, cp_email, establishment_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'clientBackgrounds' => array(self::HAS_MANY, 'ClientBackground', 'client_contact_person_id'),
			'establishment' => array(self::BELONGS_TO, 'Establishment', 'establishment_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cp_lastname' => 'Cp Lastname',
			'cp_firstname' => 'Cp Firstname',
			'cp_middlename' => 'Cp Middlename',
			'cp_cellphone_no' => 'Cp Cellphone No',
			'cp_telephone_no' => 'Cp Telephone No',
			'cp_email' => 'Cp Email',
			'establishment_id' => 'Establishment',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('cp_lastname',$this->cp_lastname,true);
		$criteria->compare('cp_firstname',$this->cp_firstname,true);
		$criteria->compare('cp_middlename',$this->cp_middlename,true);
		$criteria->compare('cp_cellphone_no',$this->cp_cellphone_no);
		$criteria->compare('cp_telephone_no',$this->cp_telephone_no);
		$criteria->compare('cp_email',$this->cp_email,true);
		$criteria->compare('establishment_id',$this->establishment_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}